package mylib.archive.y2012.m08.SNSS_R3;

import mylib.dir.FastInputReader;
import mylib.dir.MatrixUtils;
import mylib.dir.OutputUtils;

import java.io.PrintWriter;
import java.util.Arrays;

public class taskB {
    public void solve(int testNumber, FastInputReader in, PrintWriter out) {
        int m = in.nextInt();
        int n = in.nextInt();
        int r = in.nextInt();
        int[][] d = new int[n][n];
        MatrixUtils.fill(d, Integer.MAX_VALUE / 2);
        for (int i = 0; i < n; ++i)
            d[i][i] = 0;
        for (int i = 0; i < r; ++i) {
            int x = in.nextInt() - 1;
            int y = in.nextInt() - 1;
            int l = in.nextInt();
            d[x][y] = Math.min(d[x][y], l);
            d[y][x] = Math.min(d[y][x], l);
        }
        for (int k = 0; k < n; ++k)
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
        boolean[][] graph = new boolean[m][n];
        for (int i = 0; i < m; ++i) {
            int start = in.nextInt() - 1;
            int time = in.nextInt();
            for (int j = 0; j < n; ++j)
                if (d[start][j] == time)
                    graph[i][j] = true;
        }
        int[] matching = matching(graph, m, n);
        if (matching == null) {
            out.println(-1);
        } else {
            OutputUtils.outArray(out, matching);
        }
    }

    private int[] matching(boolean[][] graph, int m, int n) {
        int[] assign = new int[m];
        boolean[] yet = new boolean[n];
        for (int i = 0; i < m; ++i) {
            int cnt = 0;
            int what = -1;
            for (int to = 0; to < n; ++to) {
                if (graph[i][to] && !yet[to]) {
                    yet[to] = true;
                    int tmp = kuhn(graph, m, n, i + 1, yet);
                    if (tmp == m - i - 1) {
                        ++cnt;
                        what = to;
                    }
                    yet[to] = false;
                }
            }
            if (cnt == 0 || cnt > 1) {
                return null;
            }
            yet[what] = true;
            assign[i] = what + 1;
        }
        return assign;
    }

    private int kuhn(boolean[][] graph, int m, int n, int start, boolean[] yet) {
        int ans = 0;
        int[] matching = new int[n];
        Arrays.fill(matching, -1);

        for (int i = start; i < m; ++i) {
            if (dfs(i, graph, matching, new boolean[m], yet)) ++ans;
        }
        return ans;
    }

    private boolean dfs(int v, boolean[][] graph, int[] matching, boolean[] used, boolean[] yet) {
        if (used[v])
            return false;
        used[v] = true;
        for (int i = 0; i < graph[v].length; ++i) {
            if (yet[i])
                continue;
            if (graph[v][i] && (matching[i] == -1 || dfs(matching[i], graph, matching, used, yet))) {
                matching[i] = v;
                return true;
            }
        }
        return false;
    }
}
